<template>
  <div class="person">
    <h1>情况一：监视【ref】定义的【基本类型】数据</h1>
    <h2>sum: {{ sum }}</h2>
    <button @click="changeSum">changeSum</button>
  </div>
</template>

<script lang="ts" setup name="Person">
import { watch, ref } from "vue";
// data
let sum = ref(0);
// function
function changeSum() {
  sum.value += 1;
}
//watch
// 情况一：监视【ref】定义的【基本类型】数据
const stopWatch = watch(sum, (newVal, oldVal) => {
  console.log("sum is muted", newVal, oldVal);
  if (newVal >= 10) {
    // 停止监视
    stopWatch()
  }
});


</script>

<style scoped>
.person {
  background-color: skyblue;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
button {
  margin: 0 5px;
}
</style>
